/*
 * Generated file. 
 * 
 * TopicThread.java
 */
package xsp;

import com.ibm.xsp.page.compiled.AbstractCompiledPage;
import com.ibm.xsp.page.compiled.AbstractCompiledPageDispatcher;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import com.ibm.xsp.page.compiled.NoSuchComponentException;
import com.ibm.xsp.page.compiled.PageExpressionEvaluator;
import java.lang.String;
import javax.faces.el.MethodBinding;
import com.ibm.xsp.component.FacesPageProvider;
import com.ibm.xsp.resource.ScriptResource;
import com.ibm.xsp.resource.BundleResource;
import java.lang.Object;
import com.ibm.xsp.component.UIViewRootEx2;
import com.ibm.xsp.extlib.component.misc.UIRedirect;
import com.ibm.xsp.extlib.component.misc.RedirectPhoneRule;
import com.ibm.xsp.extlib.component.misc.RedirectTabletRule;
import com.ibm.xsp.component.xp.XspEventHandler;
import com.ibm.xsp.component.UIIncludeComposite;
import com.ibm.xsp.binding.PropertyMap;

@SuppressWarnings("all")
public class TopicThread extends AbstractCompiledPageDispatcher{

    private static final String[][] s_libraryVersions = new String[][]{
        {"com.ibm.xsp.extlib.library", "8.5.32003"},  // version of "xe:redirect"
    };
    
    public TopicThread() {
        super("8.5.1"); // version of xp:eventHandler script
    }

    protected String[][] getLibraryTagVersions() {
        return s_libraryVersions;
    }

    protected AbstractCompiledPage createPage(int pageIndex) {
        return new TopicThreadPage();
    }
    
    public static class TopicThreadPage extends AbstractCompiledPage {
        
        private static final ComponentInfo[] s_infos = new ComponentInfo[]{
            ComponentInfo.EMPTY_NORMAL, // 0 redirect
            ComponentInfo.EMPTY_NORMAL, // 1 eventHandler
            ComponentInfo.EMPTY_NORMAL, // 2 "viewtopic"
            new ComponentInfo(false, new int[]{2}), // 3 layout
            new ComponentInfo(false, new int[]{0, 1, 3}), // 4 view
        };
        
        public TopicThreadPage() {
            super(4, s_infos );
        }
        
        public int getComponentForId(String id) throws NoSuchComponentException { 
            if( "viewtopic".equals(id) )
                return 2;
            return -1;
        }
        
        public UIComponent createComponent(int id, FacesContext context,
                UIComponent parent, PageExpressionEvaluator evaluator)
                throws NoSuchComponentException { 
            switch (id) {
            case 4:
                return createView(context, parent, evaluator);
            case 0:
                return createRedirect(context, parent, evaluator);
            case 1:
                return createEventHandler(context, parent, evaluator);
            case 3:
                return createLayout(context, parent, evaluator);
            case 2:
                return createViewtopic(context, parent, evaluator);
            }
            throw new NoSuchComponentException(id);
        }
        
        protected void initIncluderAsRoot(FacesContext context,
                PageExpressionEvaluator evaluator, UIComponent root) {
            String sourceId = "/xp:view[1]/xp:this.beforePageLoad[1]/text()";
            MethodBinding beforePageLoad = evaluator.createMethodBinding(root,
                    "#{javascript:init()}",
                    null,null, sourceId);
            FacesPageProvider asPageProvider = root instanceof FacesPageProvider ?
                    (FacesPageProvider) root : null;
            if( null != asPageProvider ){
                asPageProvider.setBeforePageLoad(beforePageLoad);
            }
            ScriptResource resources = new ScriptResource();
            resources.setComponent(root);
            resources.setClientSide(false);
            resources.setSrc("/mobile-server.jss");
            if( null != asPageProvider ){
                asPageProvider.addResource(resources);
            }
            ScriptResource resources2 = new ScriptResource();
            resources2.setComponent(root);
            resources2.setClientSide(false);
            resources2.setSrc("/xpServerSide.jss");
            if( null != asPageProvider ){
                asPageProvider.addResource(resources2);
            }
            BundleResource resources3 = new BundleResource();
            resources3.setComponent(root);
            resources3.setSrc("/strings.properties");
            resources3.setVar("res");
            if( null != asPageProvider ){
                asPageProvider.addResource(resources3);
            }
            ScriptResource resources4 = new ScriptResource();
            resources4.setComponent(root);
            resources4.setClientSide(false);
            resources4.setSrc("/xpCGIVariables.jss");
            if( null != asPageProvider ){
                asPageProvider.addResource(resources4);
            }
            ScriptResource resources5 = new ScriptResource();
            resources5.setComponent(root);
            resources5.setClientSide(true);
            resources5.setSrc("/largeContent.js");
            if( null != asPageProvider ){
                asPageProvider.addResource(resources5);
            }
            String pageTitleBnd = "#{javascript:@DbTitle()}";
            String sourceId2 = "/xp:view[1]/@pageTitle";
            Object pageTitle = evaluator.getBindingValue(root, pageTitleBnd, sourceId2, String.class);
            evaluator.setValue(root, "pageTitle", pageTitle, false, false);
        }

        private UIComponent createView(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            UIViewRootEx2 result = new UIViewRootEx2();
            initViewRoot(result);
            String sourceId = "/xp:view[1]/xp:this.beforePageLoad[1]/text()";
            MethodBinding beforePageLoad = evaluator.createMethodBinding(result,
                    "#{javascript:init()}",
                    null,null, sourceId);
            result.setBeforePageLoad(beforePageLoad);
            ScriptResource resources = new ScriptResource();
            resources.setComponent(result);
            resources.setClientSide(false);
            resources.setSrc("/mobile-server.jss");
            result.addResource(resources);
            ScriptResource resources2 = new ScriptResource();
            resources2.setComponent(result);
            resources2.setClientSide(false);
            resources2.setSrc("/xpServerSide.jss");
            result.addResource(resources2);
            BundleResource resources3 = new BundleResource();
            resources3.setComponent(result);
            resources3.setSrc("/strings.properties");
            resources3.setVar("res");
            result.addResource(resources3);
            ScriptResource resources4 = new ScriptResource();
            resources4.setComponent(result);
            resources4.setClientSide(false);
            resources4.setSrc("/xpCGIVariables.jss");
            result.addResource(resources4);
            ScriptResource resources5 = new ScriptResource();
            resources5.setComponent(result);
            resources5.setClientSide(true);
            resources5.setSrc("/largeContent.js");
            result.addResource(resources5);
            String pageTitleBnd = "#{javascript:@DbTitle()}";
            String sourceId2 = "/xp:view[1]/@pageTitle";
            Object pageTitle = evaluator.getBindingValue(result, pageTitleBnd, sourceId2, String.class);
            evaluator.setValue(result, "pageTitle", pageTitle, false, false);
            return result;
        }

        private UIComponent createRedirect(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            UIRedirect result = new UIRedirect();
            RedirectPhoneRule rules = new RedirectPhoneRule();
            rules.setComponent(result);
            rules.setUrlHash("document");
            rules.setUrl("/mobile.xsp");
            result.addRule(rules);
            RedirectTabletRule rules2 = new RedirectTabletRule();
            rules2.setComponent(result);
            rules2.setUrlHash("document");
            rules2.setUrl("/mobile.xsp");
            result.addRule(rules2);
            return result;
        }

        private UIComponent createEventHandler(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            XspEventHandler result = new XspEventHandler();
            result.setSubmit(false);
            result.setEvent("onClientLoad");
            MethodBinding script = evaluator.createMethodBinding(result,
                    "if(!dojo.exists(\"ibm.xsp.widget.layout.xspClientRCP\")){insertLinks();}",
                    null,null, null);
            result.setScript(script);
            return result;
        }

        private UIComponent createLayout(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            String resultPage = "/layout.xsp";
            UIIncludeComposite result = new UIIncludeComposite();
            result.setPageDriver(getPageParam().getPageDriver());
            result.setPageName(resultPage);
            PropertyMap propertyMap = result.getPropertyMap();
            String sourceId = "/xp:view[1]/xc:layout[1]/@navigationPath";
            String navigationPathExpr = "#{sessionScope.historyPageName}";
            propertyMap.setProperty("navigationPath", evaluator.createValueBinding(result, navigationPathExpr, sourceId,String.class));
            return result;
        }

        private UIComponent createViewtopic(FacesContext context, 
                UIComponent parent, PageExpressionEvaluator evaluator) {
            String resultPage = "/viewTopic.xsp";
            UIIncludeComposite result = new UIIncludeComposite();
            result.setPageDriver(getPageParam().getPageDriver());
            result.setPageName(resultPage);
            setId(result, "viewTopic");
            return result;
        }

    }
}
